﻿@model ArchiveModel
@using Enter.Admin.Utils
@using Enter.Admin.Enums
@using Enter.Admin.Models.DataTables;
@using Enter.Admin.Dtoes;
@using Enter.Admin.Entities
@{
    ViewData["Title"] = "档案管理 - 编辑";
    var columns = Excel.Headers<ArchiveModel>().Where(t=>t.Editable);// DataTablesColumnExt.ToList<ArchiveModel>();
}
@section Styles {
    <link href="~/plugins/bootstrap-datepicker/dist/css/bootstrap-datepicker.css" rel="stylesheet" />
    <link href="~/plugins/bootstrap-datepicker/dist/css/bootstrap-datepicker3.css" rel="stylesheet" />
    <link href="~/plugins/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css" rel="stylesheet" />
    @*<link href="~/plugins/eonasdan-bootstrap-datetimepicker/build/css/bootstrap-datetimepicker.min.css" rel="stylesheet" />*@
    <link href="~/plugins/bootstrap-select/dist/css/bootstrap-select.min.css" rel="stylesheet" />
    <style>
        div .bootstrap-select .btn.bs-placeholder {
            color: rgb(0,0,0) !important
        }

            div .bootstrap-select .btn.bs-placeholder:active, div .bootstrap-select .btn.bs-placeholder:focus, div .bootstrap-select .btn.bs-placeholder:hover {
                color: rgb(0,0,0) !important
            }

        div .bootstrap-select .btn.btn-light, div .bootstrap-select .btn.btn-white {
            color: rgb(0,0,0) !important
        }

        .btn-white:not(:disabled):not(.disabled).active, .btn-white:not(:disabled):not(.disabled):active, .show > .btn-white.dropdown-toggle {
            color: rgb(255,255,255) !important
        }
    </style>
}
@section Scripts {
    <script src="~/plugins/moment/min/moment.min.js"></script>
    <script src="~/plugins/bootstrap-datepicker/dist/js/bootstrap-datepicker.js"></script>
    <script src="~/plugins/bootstrap-datepicker/dist/locales/bootstrap-datepicker.zh-CN.min.js"></script>
    @*<script src="~/plugins/eonasdan-bootstrap-datetimepicker/build/js/bootstrap-datetimepicker.min.js"></script>*@
    <script src="~/plugins/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
    <script src="~/plugins/bootstrap-datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js"></script>
    <script src="~/plugins/bootstrap-select/dist/js/bootstrap-select.min.js"></script>
    <script src="~/plugins/parsleyjs/dist/parsley.min.js"></script>
    <script src="~/plugins/parsleyjs/dist/i18n/zh_cn.extra.js"></script>
    <script src="~/plugins/parsleyjs/dist/i18n/zh_cn.js"></script>
    <script>
        var edit = function () {
            if (!$('#form-home-edit').parsley().validate()) return;
            $.ajax({
                type: "POST",
                dataType: "json",
                url: "@Url.Action("Edit", "Home")",// ,new {id = Model.Id }
                data: $("#form-home-edit").serialize(),
                success: function (result) {
                    if (result.Success) {
                        window.location.href = "@Url.Action("Index", "Home")";
                    } else {
                        show_alert('warning', result.Message)
                    }
                },
                error: function (e) {
                    show_alert('error','网络异常.')
                }
            });
        }
        $(document).ready(function () {
            // https://getdatepicker.com/4/
            $('.datetimepicker').datetimepicker({
                clearBtn: true,
                todayBtn: true,
                autoclose: true,
                language: "zh-CN",
                format: 'yyyy-mm-dd hh:ii:ss'
            });
            // $(".datepicker").datepicker("getDate").toLocaleString();//获取
            $('.datepicker').datepicker({
                todayHighlight: true,
                language: "zh-CN",
                autoclose: true,
                clearBtn: true,
                todayBtn: true,
                format: "yyyy-mm-dd" //日期格式，详见 http://bootstrap-datepicker.readthedocs.org/en/release/options.html#format
            });
            $('.selectpicker').selectpicker('render');

            $('#form-save-button').click(function () {
                edit();
            })
        });
    </script>
}
@*@section Scripts {
        @{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
    }*@

<h1>档案管理 - 编辑</h1>
<div>
    <form asp-action="Edit" id="form-home-edit">
        <div class="panel panel-inverse" data-sortable-id="form-plugins-1">
            <!-- begin panel-heading -->
            <div class="panel-heading">
                <h4 class="panel-title">基础信息</h4>
            </div>
            <!-- end panel-heading -->
            <!-- begin panel-body -->
            <div class="panel-body row">                
                @foreach (var column in columns)
                {
                <div class="form-group col-sm-4">
                    <label class="col-form-label @(column.Required?"text-danger":"")">@column.HeaderName</label>
                    @if (column.Property.PropertyType == typeof(DateTime))
                    {
                        var dateTime = (DateTime)column.Property.GetValue(Model, null);
                        var class_str = "form-control";
                        if (column.PropertyName == "CustomerBirthday")
                        {
                            class_str += " automatic-birthday-for-CustomerID";
                        }
                        @if (column.Format == DateFormatConverter.Format_yyyyMMddHHmmss)
                        {
                            <input type="text" class="@class_str datetimepicker" id="@column.PropertyName" name="@column.PropertyName" value="@(dateTime == DateTime.MinValue ? "" : dateTime.ToString(DateFormatConverter.Format_yyyyMMddHHmmss))" @(column.Required?"data-parsley-required=\"true\"":"") placeholder=" 请选择时间" />
                        }
                        else
                        {
                            <input type="text" class="@class_str datepicker" id="@column.PropertyName" name="@column.PropertyName" value="@(dateTime == DateTime.MinValue ? "" : dateTime.ToString(DateFormatConverter.Format_yyyyMMdd))" @(column.Required?"data-parsley-required=\"true\"":"") placeholder=" 请选择日期" />
                        }
                    }
                    else if (!string.IsNullOrWhiteSpace(column.Drop) || column.Property.PropertyType.IsEnum)
                    {
                        var drop = column.Drop;
                        if (column.Property.PropertyType.IsEnum)
                        {
                            drop = column.Property.PropertyType.Name;
                        }
                        var class_str = "form-control selectpicker";
                        if (column.PropertyName == "CustomerSexy")
                        {
                            class_str = class_str + " automatic-sexy-for-CustomerID";
                        }
                        @Html.DropDownList(column.PropertyName, Tools.EnumList(drop, !column.Required), new { @class = class_str, @data_live_search = "true", @data_style = "btn-white" })
                    }
                    else if (column.Property.PropertyType == typeof(int) || column.Property.PropertyType == typeof(long))
                    {
                        <input class="form-control" type="number" id="@column.PropertyName" name="@column.PropertyName" value="@column.Property.GetValue(Model, null)" @(column.PropertyName == "Id"?"readonly=\"readonly\"":"") @(column.Required?"data-parsley-required=\"true\"":"")>
                    }
                    else
                    {
                        var class_str = "form-control";
                        if (column.PropertyName == "CustomerID")
                        {
                            class_str = class_str + " automatic-card-id";
                        }
                        <input class="@class_str" type="text" id="@column.PropertyName" name="@column.PropertyName" value="@column.Property.GetValue(Model, null)" @(column.Required?"data-parsley-required=\"true\"":"")>
                    }

                </div>
                }
            </div>
            <!-- end panel-body -->
        </div>
    </form>
</div>

<div class="row">
    <input id="form-save-button" type="button" class="btn btn-primary" value="保存" />
    <a style="margin-left: 10px;" class="btn btn-primary" asp-action="Index">返回列表</a>
</div>

